<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('对账单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>开始时间：</label>
                                <input type="text" class="time-input" placeholder="请选择开始时间" name="startDate"/>
                            </li>
                            <li>
                                <label>结束时间：</label>
                                <input type="text" class="time-input" placeholder="请选择结束时间" name="endDate"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:lacksRole="PartnerAdmin,PartnerUser">
                    <i class="fa fa-plus"></i> 添加
                </a>

                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="account:account:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="account:account:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="account:account:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('account:account:edit')}]];
        var removeFlag = [[${@permission.hasPermi('account:account:remove')}]];
        var prefix = ctx + "account/account";

        let type=[[${type}]];
        let contractId=[[${contractId}]];


        let url=prefix + "/list";
        //详情
        if(!isEmptyString(type)){
            url= url+"?type="+type
        }
        if(!isEmptyString(type) && !isEmptyString(contractId)){
           url= url+"&contractId="+contractId;
        }

        if(isEmptyString(contractId)){
            $(".btn-success").addClass("hidden");
        }

        function isSell(){
            return type==1;
        }

        $(function() {
            var options = {
                url: url,
                createUrl: prefix + "/add?contractId="+contractId,
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "accountId",
                sortOrder:"desc",
                modalName: isSell()?"收款对账单":"付款对账单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'accountId',
                    title: 'ID',
                    visible: false
                },
                    {
                        field: 'accountNo',
                        title: '账单号',
                    },
                {
                    field: 'startDate',
                    title: '开始时间'
                },
                {
                    field: 'endDate',
                    title: '结束时间'
                },
                {
                    field: 'totalMoney',
                    title: isSell()?'账单总金额':'账单总金额',
                },
                {
                    field: 'useMoney',
                    title: isSell()?'已经收款金额':'已经付款金额'
                },
                {
                    field: 'remainMoney',
                    title: isSell()?'待收款金额':'待付款金额'
                },

                {
                    field: 'status',
                    title: '状态',
                    visible: false,
                },
                    {
                        field: 'createTime',
                        title: '创建时间'
                    },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var caiwu=isSell()?'收款':'付款';
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openDetail(\'' + row.accountId + '\')"><i class="fa "></i>对账单详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openContractCaiWu(\'' + row.accountId + '\')"><i class="fa "></i>'+caiwu+'</a> ');

                        //actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.accountId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.accountId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function add(){
            if(type==financeType.fukuang){
                $.modal.open("付款对账单", ctx + "warehouse/mallStoreDetail?accountId=0&contractId="+contractId,1200,$(window).height() - 50,function (index,layero){
                    var wind = layero.find('iframe')[0].contentWindow;
                    var obj = wind.selectColumnParams();
                    if(!isEmptyString(obj)){
                        let data =obj ;
                        data.type=type;
                        data.contractId=contractId;
                        $.operate.save(prefix+"/add", data,function (result){
                            if (result.code == web_status.SUCCESS) {
                                $.modal.msg("入库成功！");
                                $.modal.close(index);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                        });
                    }
                });
            }else{
                $.modal.open("收款对账单", ctx + "warehouse/sellStoreDetail?accountId=0&contractId="+contractId,1200,$(window).height() - 50,function (index,layero){
                    var wind = layero.find('iframe')[0].contentWindow;
                    var obj = wind.selectColumnParams();
                    if(!isEmptyString(obj)){
                        var data = obj;
                        data.type=type;
                        data.contractId=contractId;
                        $.operate.save(prefix+"/add", data,function (result){
                            if (result.code == web_status.SUCCESS) {
                                $.modal.msg("入库成功！");
                                $.modal.close(index);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                        });
                    }
                });
            }

        }


        function openDetail(accountId){
            if(type==financeType.fukuang){
                openWin("付款对账单", ctx + "warehouse/mallStoreDetail?accountId="+accountId);
            }else{
                openWin("收款对账单", ctx + "warehouse/sellStoreDetail?accountId="+accountId);
            }
        }

        function openContractCaiWu(accountId){

            let title =type==financeType.shoukuang?"收款财务管理":"付款财务管理";
            openWin(title,ctx+"contractFinance/contractFinance?accountId="+accountId+"&type="+type+"&contractId="+contractId);
        }
    </script>
</body>
</html>
